package com.lanqiao.gxnushop.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanqiao.gxnushop.entity.FinancialRecords;
import com.lanqiao.gxnushop.service.FinancialRecordsService;
import com.lanqiao.gxnushop.valueObject.Financial;
import com.lanqiao.gxnushop.valueObject.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Log4j
@Tag(name = "FinancialRecordsController",description="财务记录控制器")
@RestController
public class FinancialRecordsController {
    @Autowired
    private FinancialRecordsService financialRecordsService;

    @PostMapping("/financialRecords")
    @Operation(summary="增加财务记录")
    @Parameter(name = "financialRecords",description = "财务记录recordId(自动生成),storeId(店铺Id),record(收入),description(记录描述),date(记录日期已自动生成)")
    public boolean add(FinancialRecords financialRecords)
    {
        return financialRecordsService.add(financialRecords);
    }

    @DeleteMapping("/financialRecords/deleteOne/{recordId}")
    @Operation(summary="根据财务记录id删除财务记录")
    @Parameter(name = "recordId",description = "财务记录recordId(不为null)")
    public boolean delete(String recordId)
    {
        return financialRecordsService.delete(recordId);
    }

    @DeleteMapping("/financialRecords/{storeId}")
    @Operation(summary="根据店铺id删除店铺财务记录")
    @Parameter(name = "storeId",description = "店铺storeId(不为null)")
    public boolean deleteAll(String storeId)
    {
        return financialRecordsService.deleteByStoreId(storeId);
    }

    @GetMapping("/financialRecords/selectOne/{recordId}")
    @Operation(summary="根据财务记录id查询财务记录")
    @Parameter(name = "recordId",description = "财务记录recordId(不为null)")
    public FinancialRecords findById(String recordId)
    {
        return financialRecordsService.findById(recordId);
    }

    @GetMapping("/financialRecords/{storeId}")
    @Operation(summary = "根据店铺id查询所有店铺财务记录")
    @Parameter(name = "storeId", description = "店铺storeId(不为null)")
    public PageInfo<FinancialRecords> findByStoreId(String storeId, Page pageable) {
        PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<FinancialRecords> list = financialRecordsService.findByStoreId(storeId);
        return new PageInfo<>(list);
    }

    @PutMapping("/financialRecords")
    @Operation(summary="根据recordId更新指定财务记录")
    @Parameter(name = "financialRecords",description = "财务记录recordId(不为null),更新record(收入)、description(描述)")
    public boolean update(FinancialRecords financialRecords)
    {
        return financialRecordsService.update(financialRecords);
    }

    @Operation(summary = "卖家店铺金额统计信息，传入的参数必须有 SellerId，可以模糊查询店铺名name,可以查看不同的月数信息")
    @Parameter(name = "financial",description = "Financial信息")
    @GetMapping("/financialCtrl/getList")
    public PageInfo<Financial> list (Financial financial,Page page){
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        ArrayList<Financial> list = financialRecordsService.list(financial);
        return new PageInfo<Financial>(list);
    }
}
